<template>
  <div>
    <el-container>
      <!-- 侧边栏（保留核心导航） -->
      <el-aside width="220px" class="sidebar-wrapper">
        <div class="sidebar-header">
          <div class="logo-container">
            <div class="logo-icon">
              <i class="el-icon-s-management"></i>
            </div>
            <h1 class="logo-text">AdminPanel</h1>
          </div>
        </div>
        <el-menu
            default-active="0"
            class="sidebar-menu"
            background-color="#161C2D"
            text-color="#8A93A4"
            active-text-color="#FFFFFF"
            unique-opened
        >
          <el-submenu index="1">
            <template slot="title">
              <i class="el-icon-message menu-icon"></i>
              <span class="menu-text">系统管理</span>
            </template>
            <el-menu-item index="1-1" class="menu-item">
              <router-link to="/admin/user" tag="span">用户管理</router-link>
            </el-menu-item>
            <el-menu-item index="1-2" class="menu-item">角色管理</el-menu-item>
            <el-menu-item index="1-3" class="menu-item">日志管理</el-menu-item>
          </el-submenu>
          <el-menu-item index="2" class="menu-item single-item">数据统计</el-menu-item>
          <el-menu-item index="3" class="menu-item single-item">系统设置</el-menu-item>
        </el-menu>
      </el-aside>

      <!-- 主内容区 + 极简头部（仅保留用户头像&退出） -->
      <el-container>
        <el-header class="simple-header">
          <el-dropdown class="user-dropdown" @command="handleDropdownCommand">
            <div class="user-info">
              <img :src="user.avatar" alt="用户头像" class="user-avatar">
              <span class="user-name">{{user.username}}</span>
              <i class="el-icon-arrow-down"></i>
            </div>
            <el-dropdown-menu slot="dropdown">
              <el-dropdown-item command="logout">退出登录</el-dropdown-item>
            </el-dropdown-menu>
          </el-dropdown>
        </el-header>
        <el-main >
          <router-view></router-view>
        </el-main>
      </el-container>
    </el-container>
  </div>
</template>

<script>
import {mapState} from 'vuex';

export default {
  name: "AdminView",
  data() {
    return {
    }
  },
  computed: mapState(['user']),
  methods: {
    handleDropdownCommand(command) {
      if (command === "logout") {
        console.log("退出登录")
        //退出至登录页面
        this.$router.push('/');
        // 实际项目中替换为“清除登录态 + 跳转登录页”的逻辑
        this.$message.info("退出登录成功");
        //退出后清空vuex
        this.$store.commit('setUserInfo', null);
      }
    },
  },
};
</script>

<style scoped>
/* 侧边栏样式（保留核心视觉） */
.sidebar-wrapper {
  background-color: #161C2D;
  color: #fff;
  height: 100vh;
  box-shadow: 2px 0 8px rgba(0, 0, 0, 0.15);
  z-index: 10;
}
.sidebar-header {
  height: 60px;
  display: flex;
  align-items: center;
  padding: 0 15px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.05);
}
.logo-container {
  display: flex;
  align-items: center;
}
.logo-icon {
  width: 36px;
  height: 36px;
  border-radius: 6px;
  background: linear-gradient(135deg, #409EFF 0%, #69b1ff 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  margin-right: 10px;
  box-shadow: 0 2px 10px rgba(64, 158, 255, 0.3);
}
.logo-icon i {
  color: #fff;
  font-size: 18px;
}
.logo-text {
  font-size: 18px;
  font-weight: 600;
  background: linear-gradient(90deg, #409EFF 0%, #83bfff 100%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  margin: 0;
}
.sidebar-menu {
  border-right: none;
  margin-top: 1px;
  padding-top: 10px;
}
.menu-icon {
  font-size: 18px;
  width: 24px;
  text-align: center;
}
.menu-text {
  font-size: 14px;
}
.menu-item {
  position: relative;
  transition: all 0.2s ease;
}
.el-submenu__title {
  height: 50px;
  line-height: 50px;
  padding-left: 20px !important;
}
.el-submenu__title:hover {
  background-color: rgba(255, 255, 255, 0.05);
  color: #409EFF;
}
.el-menu-item {
  height: 45px;
  line-height: 45px;
  padding-left: 45px !important;
}
.el-menu-item:hover {
  background-color: rgba(255, 255, 255, 0.05);
  color: #409EFF;
}
.el-menu-item.is-active {
  color: #409EFF !important;
  background-color: rgba(64, 158, 255, 0.1);
}
.el-menu-item.is-active::before {
  content: "";
  position: absolute;
  left: 0;
  top: 0;
  height: 100%;
  width: 3px;
  background-color: #409EFF;
}

/* 极简头部样式 */
.simple-header {
  background-color: #FFFFFF;
  height: 60px;
  padding: 0 20px;
  box-shadow: 0 2px 12px 0 rgba(0, 0, 0, 0.1);
  display: flex;
  justify-content: flex-end; /* 头像居右 */
  align-items: center;
}
.user-dropdown {
  cursor: pointer;
}
.user-info {
  display: flex;
  align-items: center;
}
.user-avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  object-fit: cover;
  margin-right: 8px;
}
.user-name {
  font-size: 14px;
  color: #333;
  margin-right: 4px;
}

/* 主内容区样式 */
.simple-main {
  background-color: #F5F7FA;
  padding: 20px;
  height: calc(100vh - 60px); /* 与头部高度适配 */
  overflow-y: auto;
}
.content {
  background-color: #FFFFFF;
  border-radius: 8px;
  padding: 24px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05);
}
.content h2 {
  font-size: 18px;
  font-weight: 600;
  margin-bottom: 16px;
}
</style>